package com.ruoyi.project.insurance.insurance.controller;

import java.util.List;
import java.util.UUID;

import com.ruoyi.framework.web.service.DictService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.insurance.insurance.domain.insurance;
import com.ruoyi.project.insurance.insurance.service.IinsuranceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * insuranceController
 * 
 * @author ruoyi
 * @date 2022-02-08
 */
@Controller
@RequestMapping("/insurance/insurance")
public class insuranceController extends BaseController
{
    private String prefix = "insurance/insurance";

    @Autowired
    private IinsuranceService insuranceService;
    @Autowired
    private DictService dictService;

    @RequiresPermissions("insurance:insurance:view")
    @GetMapping()
    public String insurance()
    {
        return prefix + "/insurance";
    }

    /**
     * 查询insurance列表
     */
    @RequiresPermissions("insurance:insurance:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(insurance insurance)
    {
        startPage();
        List<insurance> list = insuranceService.selectinsuranceList(insurance);
        return getDataTable(list);
    }

    /**
     * 导出insurance列表
     */
    @RequiresPermissions("insurance:insurance:export")
    @Log(title = "insurance", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(insurance insurance)
    {
        List<insurance> list = insuranceService.selectinsuranceList(insurance);
        ExcelUtil<insurance> util = new ExcelUtil<insurance>(insurance.class);
        return util.exportExcel(list, "insurance数据");
    }

    /**
     * 新增insurance
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存insurance
     */
    @RequiresPermissions("insurance:insurance:add")
    @Log(title = "insurance", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(insurance insurance)
    {
        insurance.setId(UUID.randomUUID().toString().replace("-","").substring(0,8));
        return toAjax(insuranceService.insertinsurance(insurance));
    }

    /**
     * 修改insurance
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        insurance insurance = insuranceService.selectinsuranceById(id);
        mmap.put("insurance", insurance);
        return prefix + "/edit";
    }

    /**
     * 修改保存insurance
     */
    @RequiresPermissions("insurance:insurance:edit")
    @Log(title = "insurance", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(insurance insurance)
    {
        return toAjax(insuranceService.updateinsurance(insurance));
    }

    /**
     * 删除insurance
     */
    @RequiresPermissions("insurance:insurance:remove")
    @Log(title = "insurance", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(insuranceService.deleteinsuranceByIds(ids));
    }

    /**
     * 根据险种名称查询险种信息
     * @param insuranceName
     * @return
     */
    @PostMapping( "/selectInsuranceByInsuranceName")
    @ResponseBody
    public insurance selectInsuranceByInsuranceName(@RequestParam String insuranceName)
    {
        return insuranceService.selectInsuranceByInsuranceName(insuranceName);
    }
}
